<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="出库单号" prop="danhao">
        <el-input
          v-model="queryParams.danhao"
          placeholder="请输入出库单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库类型" prop="chukuType">
        <el-select v-model="queryParams.chukuType" placeholder="请选择出库类型" clearable>
          <el-option
            v-for="dict in dict.type.chuku_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable>
          <el-option
            v-for="dict in dict.type.order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="销售订单编号" prop="orderDanhao">
        <el-input
          v-model="queryParams.orderDanhao"
          placeholder="请输入销售订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同编号" prop="contractCode">
        <el-input
          v-model="queryParams.contractCode"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库日期" prop="chukuDate">
        <el-date-picker clearable
          v-model="queryParams.chukuDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出库日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="接收仓库" prop="receivingStockId">
        <el-input
          v-model="queryParams.receivingStockId"
          placeholder="请输入接收仓库"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编码" prop="txm">
        <el-input
          v-model="queryParams.txm"
          placeholder="请输入设备编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:chukuInfo:add']"
        >手动出库</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleCopy"
          :disabled="multiple"
          v-hasPermi="['business:chukuInfo:add']"
        >复制</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleZxChuKu"
          v-hasPermi="['business:chukuInfo:zhixing']"
        >执行出库</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleZxUChuKu"
          v-hasPermi="['business:chukuInfo:zhixing']"
        >U8出库</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:chukuInfo:remove']"
        >撤销</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:chukuInfo:export']"
        >导出</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="success"-->
      <!--          plain-->
      <!--          icon="el-icon-edit"-->
      <!--          size="mini"-->
      <!--          :disabled="single"-->
      <!--          @click="printChu"-->
      <!--          v-hasPermi="['business:chukuInfo:zhixing']"-->
      <!--        >打印出库单</el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="chukuInfoMainList"   :row-key="getRowKeys" :expand-row-keys="expands" @expand-change="expandSelect" >
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-table @selection-change="handleSelectionChange" v-loading="loading" height="450" :row-class-name="tableRowClassName" border :data="chukuInfoList">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
              label="序号"
              align="center"
              type="index"
              width="50">
            </el-table-column>
            <el-table-column label="公司代码" align="center" prop="factoryCode" />
            <el-table-column label="公司名称" align="center" prop="factoryName" />
            <el-table-column label="出库单号" width="150" align="center" prop="danhao" />
            <el-table-column label="出库类型" width="100" align="center" prop="chukuType">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.chuku_type" :value="scope.row.chukuType"/>
              </template>
            </el-table-column>
            <el-table-column label="物料名称" width="150" show-overflow-tooltip align="center" prop="itemName" />
            <el-table-column label="物料名称（英文）" width="150" show-overflow-tooltip align="center" prop="itemNameEn" />
            <el-table-column label="物料编号"  width="200" show-overflow-tooltip align="center" prop="itemCode" />
            <el-table-column label="物料子编号" width="200" show-overflow-tooltip  align="center" prop="itemId" />
            <el-table-column label="规格型号" width="130" show-overflow-tooltip align="center" prop="spec" />
            <el-table-column label="物料单位" align="center" prop="unit" />
            <el-table-column label="批次" width="100" align="center" prop="lot" />
            <el-table-column label="计划号" width="130" show-overflow-tooltip align="center" prop="planId" />
            <el-table-column label="计划出库数量" width="130" align="center" prop="jhckNum" />
            <el-table-column label="实际出库数量" width="130" align="center" prop="ckNum" />

            <el-table-column label="出库日期" align="center" prop="chukuDate" width="100">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.chukuDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="出库类型" width="100" align="center" prop="chukuType">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.chuku_type" :value="scope.row.chukuType"/>
              </template>
            </el-table-column>
            <el-table-column label="仓库编号" width="150" show-overflow-tooltip align="center" prop="stockId" />
            <el-table-column label="仓库名称" width="150" show-overflow-tooltip align="center" prop="stockName" />
            <el-table-column label="库区编码" width="150" show-overflow-tooltip align="center" prop="kuquCode" />
            <el-table-column label="库区名称" width="150" show-overflow-tooltip align="center" prop="kuquName" />
            <el-table-column label="库位编码" width="130" show-overflow-tooltip align="center" prop="kuweiCode" />
            <el-table-column label="接收仓库" width="130" show-overflow-tooltip align="center" prop="receivingStockId" />
            <el-table-column label="客户名称" width="150" show-overflow-tooltip align="center" prop="clientName" />
            <el-table-column label="设备编码" width="130" show-overflow-tooltip align="center" prop="txm" />
            <el-table-column label="联系人" align="center" prop="pickingName" />
            <el-table-column label="联系电话" width="130" align="center" prop="pickingSegment" />
            <el-table-column label="订单类型" width="100" align="center" prop="orderType">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.order_type" :value="scope.row.orderType"/>
              </template>
            </el-table-column>
            <el-table-column label="订单数量" align="center" prop="contractNum" />
            <el-table-column label="销售订单编号" width="150" show-overflow-tooltip align="center" prop="orderDanhao" />
            <el-table-column label="合同编号" width="150" show-overflow-tooltip align="center" prop="contractCode" />
            <el-table-column label="单价" align="center" prop="unitPrice" />
            <el-table-column label="总价" align="center" prop="totalPrice" />
            <el-table-column label="物料类型" align="center" prop="className" />
            <el-table-column label="托管标识" align="center" prop="isTuoguan" />
            <el-table-column label="质量状态" align="center" prop="qualityState" />
            <el-table-column label="供应商编码" width="130" show-overflow-tooltip align="center" prop="supplyCode" />
            <el-table-column label="供应商名称" width="130" show-overflow-tooltip align="                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           " prop="supplyName" />
            <el-table-column label="制造商编码" width="130" show-overflow-tooltip align="center" prop="makerCode" />
            <el-table-column label="制造商名称" width="130" show-overflow-tooltip align="center" prop="makerName" />
            <el-table-column label="尺寸" align="center" prop="size" />
            <el-table-column label="单重" align="center" prop="singleWeight" />
            <el-table-column label="总重" align="center" prop="totalWeight" />
            <el-table-column label="使用状态" align="center" prop="useState" />
            <el-table-column label="颜色" align="center" prop="color" />
            <el-table-column label="花纹" align="center" prop="figure" />
            <el-table-column label="材质" align="center" prop="caizhi" />
            <el-table-column label="条形码" width="130" show-overflow-tooltip align="center" prop="txm" />
            <el-table-column label="托盘码" width="130" show-overflow-tooltip align="center" prop="tpm" />
            <el-table-column label="配送条形码" width="130" show-overflow-tooltip align="center" prop="pstxm" />
            <el-table-column label="配送时间" align="center" prop="psTime" width="100">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.psTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="组别" align="center" prop="zubie" />
            <el-table-column label="拣货人" align="center" prop="pickingName" />
            <el-table-column label="拣货工段位" width="130" align="center" prop="pickingSegment" />
            <el-table-column label="拣货时间" align="center" prop="pickingTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.pickingTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="条码打印次数" width="130" align="center" prop="txmPrintNum" />
            <el-table-column label="出库单打印次数" width="130" align="center" prop="ckPrintNum" />
            <el-table-column label="器具号" width="130" show-overflow-tooltip align="center" prop="utensilNo" />
            <el-table-column label="SAP凭证" width="130" show-overflow-tooltip align="center" prop="sapProof" />
            <el-table-column label="状态" width="130" show-overflow-tooltip align="center" prop="ckState" />
            <el-table-column label="接收入库回写状态" width="130" show-overflow-tooltip align="center" prop="zzhxState" />
            <el-table-column label="接收入时间" align="center" prop="zzrkTime" width="130">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.zzrkTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="接收入库备注" width="130" show-overflow-tooltip align="center" prop="zzrkRemark" />
            <el-table-column label="接收入库人" width="130" align="center" prop="zzrkName" />
            <el-table-column label="接收入库数" width="130"  align="center" prop="zzrkNum" />
            <el-table-column label="创建时间" width="160" align="center" prop="createTime" />
            <el-table-column label="创建者" align="center" prop="createBy" />
            <el-table-column label="更新时间" width="160" align="center" prop="updateTime" />
            <el-table-column label="出库人" align="center" prop="updateBy" />
            <el-table-column label="备注" width="150" show-overflow-tooltip align="center" prop="remark" />
            <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-circle-check"
                  v-if="scope.row.ckState != 1"
                  @click="handleZxChuKu(scope.row)"
                  v-hasPermi="['business:chukuInfo:zhixing']"
                >执行</el-button>
<!--                <el-button-->
<!--                   size="mini"-->
<!--                   type="text"-->
<!--                   icon="el-icon-edit"-->
<!--                   @click="handleUpdate(scope.row)"-->
<!--                   v-if="scope.row.ckState != 1"-->
<!--                   v-hasPermi="['business:chukuInfo:edit']"-->
<!--                 >修改</el-button>-->
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-if="scope.row.ckState != 1"
                  v-hasPermi="['business:chukuInfo:remove']"
                >撤销</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="出库单号" width="130" align="center" prop="danhao" />
      <el-table-column label="客户名称" width="150" show-overflow-tooltip align="center" prop="clientName" />
      <el-table-column label="设备编码" width="130" show-overflow-tooltip align="center" prop="txm" />
      <el-table-column label="接收仓库" width="130" show-overflow-tooltip align="center" prop="receivingStockId" />
      <el-table-column label="出库类型" width="100" align="center" prop="chukuType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.chuku_type" :value="scope.row.chukuType"/>
        </template>
      </el-table-column>
      <el-table-column label="出库日期" align="center" prop="chukuDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chukuDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划号" width="130" show-overflow-tooltip align="center" prop="planId" />
      <el-table-column label="销售订单编号" width="150" show-overflow-tooltip align="center" prop="orderDanhao" />
      <el-table-column label="合同编号" width="150" show-overflow-tooltip align="center" prop="contractCode" />
      <!--
      <el-table-column label="接收单位" width="130" show-overflow-tooltip align="center" prop="receivingUnit" />
-->
     <!-- <el-table-column label="订单类型" width="100" align="center" prop="orderType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_type" :value="scope.row.orderType"/>
        </template>
      </el-table-column>-->
<!--      <el-table-column label="托管标识" align="center" prop="isTuoguan" />
      <el-table-column label="质量状态" align="center" prop="qualityState" />-->
      <el-table-column label="操作" width="100" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-printer"
            @click="printChu(scope.row)"
            v-hasPermi="['business:chukuInfo:print']"
          >打印出库单</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出库单对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="1600px" append-to-body>
      <el-form ref="form" style="margin-top: -25px;" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item  label="出库类型" prop="chukuType">
              <el-select @change="handChangeChukuType" v-model="form.chukuType" placeholder="请选择出库类型">
                <el-option
                  v-for="dict in dict.type.chuku_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出库日期" prop="chukuDate">
              <el-date-picker clearable
                              v-model="form.chukuDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择出库日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单类型" prop="orderType">
              <el-select v-model="form.orderType" placeholder="请选择订单类型">
                <el-option
                  v-for="dict in dict.type.order_type"
                  :key="dict.value"
                  :label="dict.label" :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>

          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="销售订单编号" prop="orderDanhao">
              <el-input v-model="form.orderDanhao" placeholder="请输入销售订单编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同编号" prop="contractCode">
              <el-input v-model="form.contractCode" placeholder="请输入合同编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
          <!--  <el-form-item label="客户名称" prop="clientCode">
              <el-select @change="nameSelect" filterable  :clearable="true"  v-model="form.clientCode" placeholder="请选择客户名称">
                <el-option
                  v-for="item in hbList"
                  :key="item.clientCode"
                  :label="item.clientName"
                  :value="item.clientCode">
                  <span style="float: left">{{ item.clientName }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.clientCode }}</span>
                </el-option>
              </el-select>
            </el-form-item>-->
            <el-form-item label="客户名称" prop="clientName">
              <el-input v-model="form.clientName" placeholder="请输入客户名称" />
            </el-form-item>
          </el-col>
         <!-- <el-col :span="8">
             <el-form-item label="领料人" prop="llName">
               <el-input v-model="form.llName" placeholder="请输入领料人" />
             </el-form-item>
          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="设备编码" prop="txm">
              <el-input v-model="form.clientName" placeholder="请输入设备编码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="pickingName">
              <el-input v-model="form.clientName" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="pickingSegment">
              <el-input v-model="form.clientName" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
         <!-- <el-col :span="8">
          <el-form-item label="接收单位" prop="receivingUnit">
            <treeselect @select="handleSelect"  v-model="form.receivingUnit" :clearable="true" :options="deptOptions" :show-count="true" placeholder="请选择接收单位" />
          </el-form-item>
          </el-col>-->
          <el-col :span="8">
            <el-form-item label="接收仓库" prop="receivingStockId">
             <!-- <el-select @change="ckChange"   v-model="form.receivingStockId" placeholder="请选择接收仓库" clearable>
                <el-option
                  v-for="dict in warehouseinfo"
                  :key="dict.stockCode"
                  :label="dict.stockName"
                  :value="dict.stockCode"
                />
              </el-select>-->
              <el-select @change="ckChange"  filterable  v-model="form.receivingStockId" placeholder="请选择接收仓库" clearable>
                <el-option
                  v-for="dict in warehouseinfo"
                  :key="dict.kuweiJmCode"
                  :label="dict.kuweiJmCode"
                  :value="dict.kuweiJmCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出库原因" prop="zubie">
              <el-input v-model="form.zubie" placeholder="请输出库原因" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注" prop="remark">
              <el-input   type="textarea" v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <!--<el-row>
          <el-col :span="8">
            <el-form-item label="拣货人" prop="pickingName">
              <el-input v-model="form.pickingName" placeholder="请输入拣货人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="拣货工段位" prop="pickingSegment">
              <el-input v-model="form.pickingSegment" placeholder="请输入拣货工段位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="拣货时间" prop="pickingTime">
              <el-date-picker clearable
                              v-model="form.pickingTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择拣货时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>-->
      <!--  <el-row>

        </el-row>-->
        <el-row>
          <el-col :span="24">
            <ChukuDetailAdd :getForm="form" ref="chukuinfoAdd"></ChukuDetailAdd>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改出库单对话框 -->
    <el-dialog :close-on-click-modal="false" :title="copy.title" :visible.sync="copy.open" width="1600px" append-to-body>
      <el-form ref="form" style="margin-top: -25px;" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item  label="出库类型" prop="chukuType">
              <el-select  v-model="form.chukuType" placeholder="请选择出库类型">
                <el-option
                  v-for="dict in dict.type.chuku_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出库日期" prop="chukuDate">
              <el-date-picker clearable
                              v-model="form.chukuDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择出库日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单类型" prop="orderType">
              <el-select v-model="form.orderType" placeholder="请选择订单类型">
                <el-option
                  v-for="dict in dict.type.order_type"
                  :key="dict.value"
                  :label="dict.label" :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>

          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="销售订单编号" prop="orderDanhao">
              <el-input v-model="form.orderDanhao" placeholder="请输入销售订单编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同编号" prop="contractCode">
              <el-input v-model="form.contractCode" placeholder="请输入合同编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--  <el-form-item label="客户名称" prop="clientCode">
                <el-select @change="nameSelect" filterable  :clearable="true"  v-model="form.clientCode" placeholder="请选择客户名称">
                  <el-option
                    v-for="item in hbList"
                    :key="item.clientCode"
                    :label="item.clientName"
                    :value="item.clientCode">
                    <span style="float: left">{{ item.clientName }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.clientCode }}</span>
                  </el-option>
                </el-select>
              </el-form-item>-->
            <el-form-item label="客户名称" prop="clientName">
              <el-input v-model="form.clientName" placeholder="请输入客户名称" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
              <el-form-item label="领料人" prop="llName">
                <el-input v-model="form.llName" placeholder="请输入领料人" />
              </el-form-item>
           </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="设备编码" prop="txm">
              <el-input v-model="form.clientName" placeholder="请输入设备编码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="pickingName">
              <el-input v-model="form.clientName" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="pickingSegment">
              <el-input v-model="form.clientName" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="8">
           <el-form-item label="接收单位" prop="receivingUnit">
             <treeselect @select="handleSelect"  v-model="form.receivingUnit" :clearable="true" :options="deptOptions" :show-count="true" placeholder="请选择接收单位" />
           </el-form-item>
           </el-col>-->
          <el-col :span="8">
            <el-form-item label="接收仓库" prop="receivingStockId">
              <!-- <el-select @change="ckChange"   v-model="form.receivingStockId" placeholder="请选择接收仓库" clearable>
                 <el-option
                   v-for="dict in warehouseinfo"
                   :key="dict.stockCode"
                   :label="dict.stockName"
                   :value="dict.stockCode"
                 />
               </el-select>-->
              <el-select @change="ckChange"  filterable  v-model="form.receivingStockId" placeholder="请选择接收仓库" clearable>
                <el-option
                  v-for="dict in warehouseinfo"
                  :key="dict.kuweiJmCode"
                  :label="dict.kuweiJmCode"
                  :value="dict.kuweiJmCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出库原因" prop="zubie">
              <el-input v-model="form.zubie" placeholder="请输出库原因" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注" prop="remark">
              <el-input   type="textarea" v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <!--<el-row>
          <el-col :span="8">
            <el-form-item label="拣货人" prop="pickingName">
              <el-input v-model="form.pickingName" placeholder="请输入拣货人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="拣货工段位" prop="pickingSegment">
              <el-input v-model="form.pickingSegment" placeholder="请输入拣货工段位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="拣货时间" prop="pickingTime">
              <el-date-picker clearable
                              v-model="form.pickingTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择拣货时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>-->
        <!--  <el-row>

          </el-row>-->
        <el-row>
          <el-col :span="24">
            <ChukuDetailCopy :getForm="form" ref="chukuinfoCopy"></ChukuDetailCopy>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitCopyForm">确 定</el-button>
        <el-button @click="copy.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <div style="width: 100%;display: none">
      <div style="width: 100%;font-size: 20px;" ref="printDan">
        <div style="width: 100%;text-align: center;display: flex;margin-top: 20px" >
          <div style="display: inline-block;margin-bottom: 10px;width: 10%;margin-left: 20px" class="qrcode" ref="qrCodeUrl"></div>
          <div style="display: block;height: 80px;width: 90%;">
            <div style="height: 40px;line-height: 40px;text-align: center;font-size: 24px;font-weight: 800">出库单</div>
            <div style="height: 40px;line-height: 40px;text-align: left;font-size: 14px">
              <div style="width: 33%;float: left;margin-left: 5px">订单号：{{formData.orderDanhao}}</div>
              <div style="width: 33%;float: left">接收单位：{{formData.clientName}}</div>
              <div style="width: 33%;float: left">出库单号：{{formData.danhao}}</div>
            </div>
          </div>
        </div>
        <div style="width: 100%;margin-top: 10px;margin-bottom: 10px">
          <div style="width: 100%;display: flex;font-size: 14px;text-align: center;border-top: 2px solid black;border-bottom: 2px solid black;height: 30px;line-height: 30px">
            <div style="width: 5%;border-right: 1px solid black">序号</div>
            <div style="width: 15%;border-right: 1px solid black">物料子编号</div>
            <div style="width: 15%;border-right: 1px solid black">物料名称</div>
            <div style="width: 10%;border-right: 1px solid black">规格型号</div>
            <div style="width: 5%;border-right: 1px solid black">单位</div>
            <div style="width: 10%;border-right: 1px solid black">批次</div>
            <div style="width: 8%;border-right: 1px solid black">计划数量</div>
            <div style="width: 8%;border-right: 1px solid black">出库数量</div>
            <div style="width: 10%;border-right: 1px solid black">出库库位</div>
            <div style="width: 14%">备注</div>
          </div>
          <div style="display: flex;font-size: 14px;text-align: center;border-bottom: 1px solid black" v-for="(item,index) in chukuInfoList2" :key="index">
            <div style="width: 5%;border-right: 1px solid black">{{index+1}}</div>
            <div style="width: 15%;border-right: 1px solid black">{{item.itemId}}</div>
            <div style="width: 15%;border-right: 1px solid black">{{item.itemName}}</div>
            <div style="width: 10%;border-right: 1px solid black">{{item.spec}}</div>
            <div style="width: 5%;border-right: 1px solid black">{{item.unit}}</div>
            <div style="width: 10%;border-right: 1px solid black">{{item.lot}}</div>
            <div style="width: 8%;border-right: 1px solid black">{{item.jhckNum}}</div>
            <div style="width: 8%;border-right: 1px solid black">{{item.ckNum}}</div>
            <div style="width: 10%;border-right: 1px solid black">{{item.kuweiCode}}</div>
            <div style="width: 14%">{{item.remark}}</div>
          </div>
        </div>

        <div style="width: 100%;text-align: left;display: flex;font-size: 14px" >
          <div style="width: 25%">公司名称：{{formData.factoryName}}</div>
          <div style="width: 25%">出库单位：</div>
          <div style="width: 25%">出库人：{{formData.createBy}}</div>
          <div style="width: 25%">出库日期：{{formData.chukuDate}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mainListChukuInfo,listChukuInfo, getChukuInfo, delChukuInfo, addChukuInfo,copyAddChukuInfo, updateChukuInfo,zhixingChuku,zhixingUChuku} from "@/api/business/chukuInfo";
import {lisAllFiles} from "@/api/sales/clientFiles";
import { getWarehouseInfoByDeptId } from "@/api/base/warehouseinfo";
import { getListWarehouseinfo } from "@/api/base/warehouseinfo";
import { listWarehouseinfoKuweiAll} from "@/api/base/warehouseinfoKuwei";
import ChukuDetailAdd from './chukuinfoAdd';
import ChukuDetailCopy from './chukuinfoCopy';
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import QRCode from "qrcodejs2";
import print from 'print-js';

export default {
  components: {
    ChukuDetailAdd,Treeselect,ChukuDetailCopy
  },
  name: "ChukuInfoMain",
  dicts: ['order_type', 'chuku_type'],
  data() {
    return {
      formData:{},
      danhao:'',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库单表格数据
      chukuInfoMainList: [],
      chukuInfoList: [],
      chukuInfoList2:[],
      warehouseinfo:[],
      hbList:[],
      expands:[],
      // 部门树选项
      deptOptions: undefined,
      getRowKeys(row) {
        return row.id
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      copy:{
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryName: null,
        factoryCode: null,
        danhao: null,
        chukuType: null,
        orderType: null,
        orderDanhao: null,
        contractCode: null,
        contractNum: null,
        jhckNum: null,
        ckNum: null,
        chukuDate: null,
        itemName: null,
        itemNameEn: null,
        itemId: null,
        spec: null,
        unit: null,
        lot: null,
        supplyId: null,
        supplyName: null,
        stockId: null,
        stockName: null,
        kuquCode: null,
        kuquName: null,
        kuweiCode: null,
        itemCode: null,
        price: null,
        totalPrice: null,
        unitPrice: null,
        classId: null,
        className: null,
        isTuoguan: null,
        qualityState: null,
        makerCode: null,
        makerName: null,
        size: null,
        singleWeight: null,
        totalWeight: null,
        useState: null,
        color: null,
        figure: null,
        caizhi: null,
        txm: null,
        tpm: null,
        pstxm: null,
        psTime: null,
        zubie: null,
        pickingName: null,
        pickingSegment: null,
        pickingTime: null,
        txmPrintNum: null,
        ckPrintNum: null,
        utensilNo: null,
        sapProof: null,
        ckState: '',
        zzhxState: null,
        zzrkTime: null,
        zzrkRemark: null,
        zzrkName: null,
        zzrkNum: null,
        clientName: null,
        receivingStockId: null,
      },
      queryParams2: {
        pageNum: 1,
        pageSize: 1000,
        danhao: null
      },
      queryParams3: {
        pageNum: 1,
        pageSize: 1000,
        danhao: null
      },
      queryParams4: {
        pageNum: 1,
        pageSize: 1000,
        deptId: null
      },
      // 表单参数
      form: {
        infoList:[]
      },
      // 表单校验
      rules: {
        chukuType: [
          { required: true, message: "请选择出库类型", trigger: "blur" }
        ],
        chukuDate: [
          { required: true, message: "请输入出库日期", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getTreeselect();
    lisAllFiles().then(response => {
      this.hbList = response.rows;
    });
    /* getListWarehouseinfo().then(response => {
      this.warehouseinfo = response.data;
    });*/
    listWarehouseinfoKuweiAll().then(response => {
      this.warehouseinfo = response.data;
    });
  },
  methods: {
    async printChu(row){
      this.formData = row
      this.danhao = row.danhao
      let danhao = row.danhao
      this.queryParams3.danhao = danhao
      await listChukuInfo(this.queryParams3).then(response => {
        this.chukuInfoList2 = response.rows;
      });
      this.$refs.qrCodeUrl.innerHTML="";
      new QRCode(this.$refs.qrCodeUrl, {
        text: danhao, //二维码内容
        width: 80,
        height: 80,
      })
      setTimeout(()=>{
        this.priDan()
      },200)
    },
    priDan(){

      const style = '@page { margin:0;margin-top:30px !important;padding-bottom:20px !important; } ' +'@media print { #title{ font-size:40px};#title1{ font-size:40px }  ' ;
      printJS({
        printable:this.$refs.printDan,
        type:'html',
        header:'',
        targetStyles:['*'],
        scanStyles: false,
        style:style,
        onPrintDialogClose: () => {
          console.log('弹窗关闭');
        },
        onLoadingEnd:()=>{
          console.log('加载完毕')
        }
      })
    },
    tableRowClassName({row, rowIndex}) {
      console.log(row)
      if (row.ckState == 0) {
        return 'warning-row';
      } else{
        return '';
      }

    },
    /** 查询出库单列表 */
    getList() {
      this.loading = true;
      mainListChukuInfo(this.queryParams).then(response => {
        this.chukuInfoMainList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询出库单列表 */
    getList2() {
      listChukuInfo(this.queryParams2).then(response => {
        this.chukuInfoList = response.rows;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    expandSelect(row, expandedRows) {
      this.expands = []
      if (expandedRows.length > 0) {
        row ? this.expands.push(row.id) : ''
        this.queryParams2.danhao=row.danhao
        this.getList2();
      }
    },
    nameSelect(e){
      let result = this.hbList.find(item => item.clientCode ==e)
      this.form.clientName = result.clientName
     /* this.warehouseinfo =[];
      this.form.receivingStockId=null;
      getWarehouseInfoByDeptId(selectedNodes.id).then(response => {
        this.warehouseinfo = response.data;
      });*/
    },
    handleSelect(selectedNodes) {
      this.warehouseinfo =[];
      this.form.receivingStockId=null;
      getWarehouseInfoByDeptId(selectedNodes.id).then(response => {
        this.warehouseinfo = response.data;
      });
    },
    ckChange(){
      this.$forceUpdate();
    },
    handleClear(){
      alert("清楚了")
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryName: null,
        factoryCode: null,
        danhao: null,
        chukuType: null,
        orderType: null,
        orderDanhao: null,
        contractCode: null,
        contractNum: null,
        jhckNum: null,
        ckNum: null,
        chukuDate: new Date(),
        itemName: null,
        itemNameEn: null,
        itemId: null,
        spec: null,
        unit: null,
        lot: null,
        supplyId: null,
        supplyName: null,
        stockId: null,
        stockName: null,
        kuquCode: null,
        kuquName: null,
        kuweiCode: null,
        itemCode: null,
        price: null,
        totalPrice: null,
        unitPrice: null,
        classId: null,
        className: null,
        isTuoguan: null,
        qualityState: null,
        makerCode: null,
        makerName: null,
        size: null,
        singleWeight: null,
        totalWeight: null,
        useState: null,
        color: null,
        figure: null,
        caizhi: null,
        txm: null,
        tpm: null,
        pstxm: null,
        psTime: null,
        zubie: null,
        pickingName: null,
        pickingSegment: null,
        pickingTime:  new Date(),
        txmPrintNum: null,
        ckPrintNum: null,
        utensilNo: null,
        sapProof: null,
        ckState: null,
        zzhxState: null,
        zzrkTime: null,
        zzrkRemark: null,
        zzrkName: null,
        zzrkNum: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        receivingUnit: null,
        receivingStockId: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handChangeChukuType(value){
      this.reset();
      this.form.chukuType=value;
      this.$refs.chukuinfoAdd.chukuinfoAddList=[];
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "手动出库";
      setTimeout(() => {
        this.$refs.chukuinfoAdd.chukuInfoAddlistReset();
      }, 10);
    },
    /** 复制按钮操作 */
    handleCopy() {
      this.reset();
      this.copy.open = true;
      this.copy.title = "复制出库";
      setTimeout(() => {
        this.$refs.chukuinfoCopy.chukuInfoCopylistReset( this.ids);
      }, 10);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getChukuInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改出库单";
        setTimeout(() => {
          this.$refs.chukuinfoAdd.chukuInfoUpdatelistReset(response.data);
        }, 10);
      });
    },
    /*执行入库*/
    handleZxChuKu(row){
      const id = row.id || this.ids
      this.$modal.confirm('是否确认执行出库吗?').then(function() {
        return zhixingChuku(id);
      }).then(() => {
        this.getList2();
        this.$modal.alertSuccess("出库成功");
      }).catch(() => {});
    },
    /*执行U8出库*/
    handleZxUChuKu(row){
      const id = row.id || this.ids
      this.$modal.confirm('是否确认执行U8出库吗?').then(function() {
        return zhixingUChuku(id);
      }).catch(() => {});
    },

    /** 提交按钮 */
    submitForm() {
      let chukuinfoAddList= this.$refs.chukuinfoAdd.chukuinfoAddList;
      if(chukuinfoAddList.length==0){
        this.$modal.alertWarning('请选择需要出库的物料!')
        return;
      }
      for(var i=0;i<chukuinfoAddList.length;i++){
        if(chukuinfoAddList[i].ckNum==''||chukuinfoAddList[i].ckNum==null||chukuinfoAddList[i].ckNum==undefined|| chukuinfoAddList[i].ckNum<=0){
          this.$modal.alertWarning('出库数量不能为空或为0')
          return;
        }
        /*  if(chukuinfoAddList[i].unitPrice==''||chukuinfoAddList[i].unitPrice==null||chukuinfoAddList[i].unitPrice==undefined){
            this.$modal.alertWarning('单价不能为空')
            return;
          }*/
        if(chukuinfoAddList[i].ckNum>chukuinfoAddList[i].kyNum){
          this.$modal.alertWarning('出库数量不能大于可用库存数量')
          return;
        }
      }
      if(this.form.chukuType=='4' || this.form.chukuType=='10' || this.form.chukuType=='12') {
        // if(this.form.receivingUnit==null || this.form.receivingUnit==""){
        //   this.$modal.alertWarning('请选择接收单位')
        //   return;
        // }
        if (this.form.receivingStockId == null || this.form.receivingStockId == "") {
          this.$modal.alertWarning('请选择接收仓库')
          return;
        }
      }
      this.form.infoList=chukuinfoAddList;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateChukuInfo(this.form).then(response => {
              this.$modal.alertSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addChukuInfo(this.form).then(response => {
              this.$modal.alertSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    submitCopyForm() {
      let chukuinfoAddList= this.$refs.chukuinfoCopy.chukuinfoAddList;
      if(chukuinfoAddList.length==0){
        this.$modal.alertWarning('请选择需要出库的物料!')
        return;
      }
      for(var i=0;i<chukuinfoAddList.length;i++){
        if(chukuinfoAddList[i].ckNum==''||chukuinfoAddList[i].ckNum==null||chukuinfoAddList[i].ckNum==undefined|| chukuinfoAddList[i].ckNum<=0){
          this.$modal.alertWarning('出库数量不能为空或为0')
          return;
        }
        /*  if(chukuinfoAddList[i].unitPrice==''||chukuinfoAddList[i].unitPrice==null||chukuinfoAddList[i].unitPrice==undefined){
            this.$modal.alertWarning('单价不能为空')
            return;
          }*/
       /* if(chukuinfoAddList[i].ckNum>chukuinfoAddList[i].kyNum){
          this.$modal.alertWarning('出库数量不能大于可用库存数量')
          return;
        }*/
      }
      if(this.form.chukuType=='4' || this.form.chukuType=='10' || this.form.chukuType=='12') {
        // if(this.form.receivingUnit==null || this.form.receivingUnit==""){
        //   this.$modal.alertWarning('请选择接收单位')
        //   return;
        // }
        if (this.form.receivingStockId == null || this.form.receivingStockId == "") {
          this.$modal.alertWarning('请选择接收仓库')
          return;
        }
      }
      this.form.infoList=chukuinfoAddList;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateChukuInfo(this.form).then(response => {
              this.$modal.alertSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            copyAddChukuInfo(this.form).then(response => {
              this.$modal.alertSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 撤销按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认撤销出库单编号为"' + ids + '"的数据项？').then(function() {
        return delChukuInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("撤销成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/chukuInfo/export', {
        ...this.queryParams
      }, `chukuInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
  ::v-deep .el-table .warning-row {
    background: #ffe4e1;
  }
</style>
